import { kdutils } from "kdweb-core/lib/utils"
import { ServerValues } from "../../../kds-base-define/src/ServerConfig"
import { DB } from "../db"


let recordGoldChangedTablename = "t_robot_record_changed"
let db = DB.get(ServerValues.dbLobby,"robot")
async function record_GoldChanged(h:string,userID:number,fromCount:number,toCount:number) {
	let time = kdutils.getMillionSecond()
	let date = kdutils.getFmtMoment("YYYY-MM-DD")
	let fullDate = kdutils.getFmtMoment("YYYY-MM-DD HH:mm:ss")
	db.insert(recordGoldChangedTablename,{
		userID:userID,
		from:fromCount,
		to:toCount,
		timestamp:time,
		date:date,
		fullDate:fullDate,
	})
	return true 
}

let recordRegTablename = "t_robot_record_changed"
async function record_CreateRobot(h:string,userID:number,groupID:number) {
	let time = kdutils.getMillionSecond()
	let date = kdutils.getFmtMoment("YYYY-MM-DD")
	let fullDate = kdutils.getFmtMoment("YYYY-MM-DD HH:mm:ss")
	db.insert(recordRegTablename,{
		userID:userID,
		groupID:groupID,
		timestamp:time,
		date:date,
		fullDate:fullDate,
	})
	return true 
}

export let RpcRobotRecord = {
	gold:record_GoldChanged,
	create:record_CreateRobot
}

